package main

import (
	"../../common/message"
	"../../common/utils"
	"../process"
	"fmt"
	"net"
)

type Processor struct {
	Conn net.Conn
}

func (this *Processor) ServerProcessMes(msg *message.Message) (err error) {
	
	switch msg.Type {
	case message.LoginMesType:
		up := &process.UserProcess{
			Conn: this.Conn,
		}
		up.ServerProcessLogin(msg)
	case message.RegisterMesType:
		up := &process.UserProcess{
			Conn: this.Conn,
		}
		up.ServerProcessRegister(msg)
	case message.SmsMesType:
		up := &process.SmsProcess{}
		up.SendGroupMes(msg)
	default:
	}
	return
}

func (this *Processor) StartProcess() (err error) {

	for {

		tf := &utils.Transfer{
			Conn: this.Conn,
		}

		msg, err := tf.ReadPkg()

		if err != nil {
			return err
		}
		fmt.Println("获取数据 = ", msg)

		mp := Processor{
			Conn: this.Conn,
		}

		err = mp.ServerProcessMes(&msg)
		if err != nil {
			return err
		}
	}

}
